package com.showcai.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.showcai.dao.AdminUserMapper;
import com.showcai.dao.ZhuliMapper;
import com.showcai.module.AdminUser;
import com.showcai.module.BaseModule;
import com.showcai.module.Zhuli;
import com.showcai.module.wechat.UserWechatInfo;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.service.AdminUserService;
import com.showcai.service.ServiceBase;
import com.showcai.service.ZhuliService;
import com.showcai.util.MD5Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZhuliServiceImpl extends ServiceBase implements ZhuliService {

    @Autowired
    ZhuliMapper zhuliMapper;



   private void insertZhuli(Zhuli zhuli) throws MyRunTimeExcption {
        zhuli.setCreateTime(new Date());
        zhuliMapper.insertZhuli(zhuli);
    }

    @Override
    public void selectZhuli(UserWechatInfo userWechatInfo) throws MyRunTimeExcption {

       if(userWechatInfo==null){
           throw new MyRunTimeExcption("user is null");
        }
       Zhuli zhuli=zhuliMapper.selectZhuliByOpenId(userWechatInfo.getOpenid());

        if(zhuli==null){
            zhuli=new Zhuli();
            zhuli.setCreateTime(new Date());
            zhuli.setOpenId(userWechatInfo.getOpenid());
            zhuli.setPicUrl(userWechatInfo.getHeadimgurl());
            insertZhuli(zhuli);
        }
    }

    @Override
    public List<Zhuli> zhuliList() throws MyRunTimeExcption {
        return zhuliMapper.zhuliList();
    }
}
